home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / russell / russell.lha / examples / tree_test.r < prev    next >
Text File  |  1989-12-29  |  714b  |  34 lines

  1. (* Compile tree.r first *)
  2.  
  3. (* Computes 3 * 2**n the hard way, where n is read from stdin *)
  4. let
  5.     tree == extern { "tree" };
  6.  
  7.     TREE == tree[Short];
  8.          
  9.     x == Short$New[];
  10.     t == TREE$New[]
  11. in
  12.     t := TREE$make_leaf[3];
  13.     x := get[FS];
  14.     do
  15.     x > 0 ==>
  16.             t := make_tree[t, t];
  17.         x := x - 1;
  18.     od;
  19.     let
  20.         Add_Leaves ==
  21.             func[ x: val TREE ]
  22.         {
  23.                     if  is_leaf[x] ==>
  24.                             leaf_value[x]    
  25.             #   else ==>
  26.                             Add_Leaves[left_sub_tree[x]]
  27.                             + Add_Leaves[right_sub_tree[x]]
  28.                     fi
  29.                 }
  30.     in
  31.         put[ Add_Leaves[t] ]; put["\n"]
  32.     ni
  33. ni
  34.